package proxy01;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class Dyproxy implements InvocationHandler {
    private Object object;

    public Object getObject() {
        return object;
    }

    public void setObject(Object object) {
        this.object = object;
    }

    private void doBefore() {
        System.out.println("售前服务。。。");
    }

    private void doAfter() {
        System.out.println("售后服务。。。");
    }

    public Object getInstance() {
        return Proxy.newProxyInstance(object.getClass().getClassLoader(), object.getClass().getInterfaces(), this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        doBefore();
        Object obj = method.invoke(object, args);
        doAfter();
        return obj;
    }
}
